package history;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class ManualDao implements Serializable {
	private static final long serialVersionUID = -657461649479545L	;
	public boolean addManual(Manual manual) {
		FileOutputStream fos = null;
		ObjectOutputStream oos = null;
		String location = "";
		File file = new File(location);
		if(!file.exists() || !file.isDirectory()) {
			file.mkdir();
		}
		
		
		try {
			fos = new FileOutputStream( manual.getFileName());
			oos = new ObjectOutputStream(fos);
			oos.writeObject(manual);
			oos.close();
			fos.close();
			return true;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			try {
				if(fos != null) {
					fos.close();
				}
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			return false;
		}
		
	}
	
	@SuppressWarnings("resource")
	public Manual getManual (String fileName) {
		FileInputStream fis = null;
		ObjectInputStream ois = null;
		try {
			fis = new FileInputStream(  fileName);
			ois = new ObjectInputStream(fis);
			Manual manual =  (Manual) ois.readObject();
			ois.close();
			fis.close();
			return manual;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		
	}
	
}





